local M = {}
local Windows = {}
local Mac = {}

local defaultIM = "com.apple.keylayout.ABC"
local pinyinIM = "com.apple.inputmethod.SCIM.ITABC"
local squirrelIM = "im.rime.inputmethod.Squirrel.Hans"

-- Mac.zhCN = pinyinIM
Mac.zhCN = squirrelIM
Mac.en = defaultIM

local getChangeIM = function()
  local mode = vim.fn.mode()
  if mode == "n" then
    -- normal mode
    return Mac.en
  elseif mode == "i" then
    -- insert mode
    return Mac.zhCN
  elseif mode == "v" then
    -- visual mode
    return Mac.en
  else
    return Mac.en
  end
end

M.macFocusGained = function()
  vim.cmd(":silent :!im-select" .. " " .. getChangeIM())
end
M.macFocusLost = function()
  vim.cmd(":silent :!im-select" .. " " .. Mac.zhCN)
end
M.macInsertLeave = function()
  vim.cmd(":silent :!im-select" .. " " .. Mac.en)
end
M.macInsertEnter = function()
  vim.cmd(":silent :!im-select" .. " " .. Mac.zhCN)
end

return M
